package org.lg.dao.impl;

import org.lg.config.Repository;
import org.lg.config.Resource;
import org.lg.dao.ClazzDao;
import org.lg.entity.Clazz;
import org.lg.entity.ClazzExample;
import org.lg.mapper.ClazzMapper;
import org.lg.page.PageInfo;

import java.util.List;

@Repository("clazzDao")
public class ClazzDaoImpl implements ClazzDao {
    @Resource
    ClazzMapper clazzMapper;
    @Override
    public List<Clazz> getAllClazzs() throws Exception {

        return clazzMapper.selectByExample(null);
    }

    /**
     * 分页查询学生
     * @param pageInfo
     * @return
     */

    public List<Clazz> getClazzByPage(PageInfo pageInfo){
        ClazzExample clazzExample = new ClazzExample();
        long l = clazzMapper.countByExample(null);
        pageInfo.setItemCount((int)l);
        clazzExample.setOffset(pageInfo.getOffset());
        clazzExample.setLimit(pageInfo.getPageSize());
        return clazzMapper.selectByExample(clazzExample);
    }

    @Override
    public Clazz getClazzByCno(String cno) throws Exception {
        return clazzMapper.selectByPrimaryKey(cno);
    }

    @Override
    public Integer addClazz(Clazz clazz) throws Exception {
        return clazzMapper.insertSelective(clazz);
    }


}
